package com.gmrz.uap.aop;

import cn.hutool.json.JSONUtil;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.AccessibleObject;

/**
 * @author Wang Haifeng
 */
public class SystemBlocker implements MethodInterceptor {

    private static final Logger log = LoggerFactory.getLogger(SystemBlocker.class);


    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        //计算方法执行时间
        long start = System.currentTimeMillis();
        log.info("SystemBlocker invoke [Method]:  {}", invocation.getMethod().getName());
        Object[] arguments = invocation.getArguments();
        log.info("SystemBlocker invoke [Arguments]: {}", JSONUtil.toJsonStr(arguments));
        Object o = invocation.getThis();
        log.info("SystemBlocker invoke [This]: {}", o);
        AccessibleObject accessibleObject = invocation.getStaticPart();
        log.info("SystemBlocker invoke [StaticPart]：{}", accessibleObject);
        Object o1 = invocation.proceed();
        log.info("SystemBlocker invoke [proceed]: {}", o1);
        long end = System.currentTimeMillis();
        log.info("------------- SystemBlocker invoke [Time]: {} ms", end - start);
        return invocation.proceed();
    }
}
